
//https://www.nowcoder.com/share/jump/6027417231762870423703
package Mycode.Class053;
import java.io.*;


class Main {
    private static final int maxn = 100009;
    private static int[][] stack = new int[maxn][2];
    private static int[] nums = new int[maxn];
    private static int n;
    private static int r;
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int)in.nval;
            for (int i = 0; i < n; i ++) {
                in.nextToken(); nums[i] = (int)in.nval;
            }
            out.println(compute());

        }
        out.flush();
        out.close();
        br.close();
    }
    private static int compute() {
        int ans = 0;
        for (int curTurns, i = n - 1; i >= 0; i -- ) {
            curTurns = 0;
            while (r > 0 && stack[r - 1][0] < nums[i]) {
                curTurns = Math.max(curTurns + 1, stack[--r][1]);
                ans = Math.max(ans, curTurns);
            }
            stack[r][1] = curTurns;
            stack[r++][0] = nums[i];
        }
        return ans;
    }
}
